import React, { useEffect } from 'react'
import { Row, Col, Form, Input, Typography, Select, Button } from "antd"
import { ajax } from '../../api'
import { observer } from 'mobx-react'
import myinfo from '../../mobx/info'
import { toast } from '../../utils/commom'
import Item from 'antd/lib/list/Item'
const { Title } = Typography
//match获取参数
function Freeedit({ history, match }: any) {
    useEffect(() => {
        getOneData()
    }, [])

    const getOneData = async () => {
        let { code, result }: any = await ajax.getshoufeiitem({
            _id: match.params.aid
        })
        if (code == 200) {
            form.setFieldsValue(result)
        }
    }




    const { userInfo } = myinfo
    const onFinish = async (value: any) => {
        value.userInfo = userInfo
        let { code, result }: any = await ajax.addshoufei(value)
        if (code == 200) {
            history.push("/main/free/list")
        }

    }
    const onFinishFailed = () => {
        toast.error("请输入有效的信息")
    }
    const [form] = Form.useForm()
    return (
        <div>
            <Title level={4}>中海物业再次编辑收费项目</Title>
            <Row>
                <Col>
                    <Form
                        name="basic"
                        labelCol={{ span: 24 }}
                        wrapperCol={{ span: 24 }}
                        initialValues={{ password: "qwe123" }}
                        onFinish={onFinish}
                        onFinishFailed={onFinishFailed}
                        autoComplete="off"
                        form={form}
                    >
                        <Form.Item
                            label="项目标题"
                            name="title"
                            rules={[{ required: true, message: '请输入项目标题!' }]}
                        >
                            <Input placeholder="请输入项目标题" />
                        </Form.Item>

                        <Form.Item
                            label="项目标准内容"
                            name="content"
                            rules={[{ required: true, message: '请输入项目标准内容!' }]}
                        >
                            <Input.TextArea cols={10} rows={10} placeholder="请输入项目标准内容" />
                        </Form.Item>

                        <Form.Item
                            label="项目备注"
                            name="remarks"
                            rules={[{ required: true, message: '请输入项目备注!' }]}
                        >
                            <Input placeholder="请输入项目备注" />
                        </Form.Item>


                        <Form.Item>
                            <Row>
                                <Col span={24} >
                                    <Button type="primary" block htmlType="submit"  > 修改项目内容 </Button>
                                </Col>

                            </Row>
                        </Form.Item>
                    </Form>
                </Col>
            </Row>
        </div>
    )
}
export default observer(Freeedit)